package com.google.code.jholidays.events.properties;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import org.junit.Test;

import com.google.code.jholidays.core.EventDescriptor;
import com.google.code.jholidays.events.IEvent;
import com.google.code.jholidays.events.parameters.Offset;
import com.google.code.jholidays.moc.FixedEventMoc;

public class DependentEventPropertiesTest {

    @Test(expected = IllegalArgumentException.class)
    public void testNullDecriptor() {
	int parentID = 1;
	IEvent parent = new FixedEventMoc(parentID);
	Offset offset = new Offset(4);
	DependentEventProperties props = new DependentEventProperties(null,
		parent, offset);
	assertNull(props);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNullOffset() {
	int parentID = 1;
	int eventID = 2;
	IEvent parent = new FixedEventMoc(parentID);
	EventDescriptor desciptor = new EventDescriptor(eventID);
	DependentEventProperties props = new DependentEventProperties(
		desciptor, parent, null);
	assertNull(props);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testNullParent() {
	int eventID = 2;
	Offset offset = new Offset(4);
	EventDescriptor desciptor = new EventDescriptor(eventID);
	DependentEventProperties props = new DependentEventProperties(
		desciptor, null, offset);
	assertNull(props);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testInvalidParentID() {
	int eventID = 2;
	int parentID = eventID + 5;
	IEvent parent = new FixedEventMoc(parentID);
	Offset offset = new Offset(4);
	EventDescriptor desciptor = new EventDescriptor(eventID);
	DependentEventProperties props = new DependentEventProperties(
		desciptor, parent, offset);
	assertNull(props);

    }

    @Test
    public void testDependentEventProperties() {
	int eventID = 1;
	int parentID = 2;
	IEvent parent = new FixedEventMoc(parentID);
	Offset offset = new Offset(4);
	EventDescriptor desciptor = new EventDescriptor(eventID, parentID);
	DependentEventProperties props = new DependentEventProperties(
		desciptor, parent, offset);
	assertNotNull(props);
    }

    @Test
    public void testGetOffset() {
	int eventID = 1;
	int parentID = 2;
	IEvent parent = new FixedEventMoc(parentID);
	Offset offset = new Offset(4);
	EventDescriptor desciptor = new EventDescriptor(eventID, parentID);
	DependentEventProperties props = new DependentEventProperties(
		desciptor, parent, offset);
	assertNotNull(props);

	assertNotNull(props.getOffset());
	assertSame(props.getOffset(), offset);
    }

    @Test
    public void testGetDescriptor() {
	int eventID = 1;
	int parentID = 2;
	IEvent parent = new FixedEventMoc(parentID);
	Offset offset = new Offset(4);
	EventDescriptor desciptor = new EventDescriptor(eventID, parentID);
	DependentEventProperties props = new DependentEventProperties(
		desciptor, parent, offset);
	assertNotNull(props);

	assertNotNull(props.getDescriptor());
	assertSame(props.getDescriptor(), desciptor);
    }

    @Test
    public void testGetParent() {
	int eventID = 1;
	int parentID = 2;
	IEvent parent = new FixedEventMoc(parentID);
	Offset offset = new Offset(4);
	EventDescriptor desciptor = new EventDescriptor(eventID, parentID);
	DependentEventProperties props = new DependentEventProperties(
		desciptor, parent, offset);
	assertNotNull(props);

	assertNotNull(props.getParent());
	assertSame(props.getParent(), parent);
    }

}
